﻿using System;

namespace DotNetCommon.Validate.Annotations;

/// <summary>
/// 不能是某个值, 示例:
/// <code>
/// [VNotBeString("Normal", ignoreCase:false)]
/// public string Type { get; set; }
/// </code>
/// </summary>
/// <remarks>注意: 当属性不是字符串时, 会先调用 ToString() 转为字符串再进行判断, 这可以用于对非字符串类型的校验</remarks>
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
public sealed class VNotBeStringAttribute(string value, bool ignoreCase = false, string errorMessage = null) : Attribute, IValidateAction
{
    public string Value { get; internal set; } = value;
    public bool IgnoreCase { get; internal set; } = ignoreCase;
    public string ErrorMessage { get; internal set; } = errorMessage;

    public void Action(IValidateContext ctx)
    {
        ValidateStringExtensions.MustNotBeStringInternal(ctx, Value, IgnoreCase, ErrorMessage);
    }
}
